# Contributor: Alan Lacerda <alacerda@alpinelinux.org>
# Maintainer: Alan Lacerda <alacerda@alpinelinux.org>
pkgname=xrdp
pkgver=0.9.23.1
pkgrel=0
pkgdesc="Open source RDP server"
url="https://www.xrdp.org/"
arch="all"
license="Apache-2.0"
install="$pkgname.post-install"
depends="xinit bash"
makedepends="autoconf automake check-dev libtool openssl-dev>3 libx11-dev
	libxfixes-dev libxrandr-dev libjpeg-turbo-dev fuse-dev linux-headers
	nasm linux-pam-dev opus-dev"
subpackages="$pkgname-doc $pkgname-dev $pkgname-openrc"
source="https://github.com/neutrinolabs/xrdp/releases/download/v$pkgver/xrdp-$pkgver.tar.gz
	xrdp.initd
	dynamic-link.patch
	remove-werror.patch
	openssl.conf
	"

# secfixes:
#   0.9.23.1-r0:
#     - CVE-2023-42822
#   0.9.23-r0:
#     - CVE-2023-40184
#   0.9.21.1-r0:
#     - CVE-2022-23468
#     - CVE-2022-23477
#     - CVE-2022-23478
#     - CVE-2022-23479
#     - CVE-2022-23480
#     - CVE-2022-23481
#     - CVE-2022-23483
#     - CVE-2022-23482
#     - CVE-2022-23484
#     - CVE-2022-23493
#   0.9.18.1-r0:
#     - CVE-2022-23613
#   0.9.15-r1:
#     - CVE-2021-36158
#   0.9.13.1-r0:
#     - CVE-2020-4044

prepare() {
	default_prepare
	./bootstrap

	# config for non-suid Xorg
	sed -i 's|^param=Xorg|param=/usr/libexec/Xorg|' sesman/sesman.ini
}

build() {
	local _simd_opt=""
	if [ "$CARCH" = "x86" ]; then
		_simd_opt="--without-simd"
	fi
	./configure \
		--prefix=/usr \
		--disable-static \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--sbindir=/usr/sbin \
		--enable-fuse \
		--enable-ipv6 \
		--enable-opus \
		--enable-pam \
		--enable-tests \
		--enable-tjpeg \
		$_simd_opt
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm0644 "$srcdir"/openssl.conf -t "$pkgdir"/etc/xrdp

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	ln -s $pkgname $pkgdir/etc/init.d/$pkgname-sesman

	# Remove keys and its configuration generated during the
	# build process
	rm -f \
		"$pkgdir"/etc/xrdp/*.pem \
		"$pkgdir"/etc/xrdp/rsakeys.ini
}

sha512sums="
92b732b85afe49c49c103c37404c66aa24fddf1583a91ec4a691044a8f02ec1abd7c834a6e0f06469e3a3bfe9fae69d90759a7ea6904ccf468271309b1fe5577  xrdp-0.9.23.1.tar.gz
22b44398f4014ee67831051d1a1a859c6f4a601d75a03b33142ce7ea1e3f00082134337efb7da69e964f4a369d2b22114973221be2131f384f9459cc8e82fc13  xrdp.initd
d04d15b40ee6498f89ee1ca7492b44861b2c8182d9a15297fe12609a16107e54fce1cb0c377f5746d46d76592ee4e9ed1cefe334bb2ea9ec2607daf86a1195c4  dynamic-link.patch
e22d17ad3d7116707bd4259592960175cf7586637228f8c37d92e60430ae38bf71d10667688e2d1db123709a074480b1f2e4e6f279c6ef421cc1c20688cde816  remove-werror.patch
c06de34e3f926d3d580a54a95a97c0fb3069c9fbade65b23bf424609aabb2a42db68eaeaa9540716b93b8d96bc3e75616612eedfa6cd55e736eee3b79c585d4f  openssl.conf
"
